package com.yt.order.provider.service.impl;

import com.yt.core.dao.filter.DynamicSQLFilterImpl;
import com.yt.core.dao.filter.QueryFilter;
import com.yt.core.service.GenericServiceImpl;
import com.yt.order.api.interfaces.OrderInfoService;
import com.yt.order.api.model.OrderInfo;
import com.yt.order.provider.dao.OrderInfoDao;

import java.util.List;

/**
 * Created by liujunshi on 15-12-30.
 */
public class OrderInfoServiceImpl extends GenericServiceImpl<OrderInfo, Long> implements OrderInfoService {
	private OrderInfoDao dao;

	public OrderInfoServiceImpl() {
	}

	public OrderInfoServiceImpl(OrderInfoDao dao) {
		super(dao);
		this.dao = dao;
	}

	@Override
	public OrderInfo getOrderByOrderNo(String orderNo) {
		QueryFilter filter = new DynamicSQLFilterImpl();
		filter.addFilter("Q_orderNo_S_EQ", orderNo);
		List<OrderInfo> list = dao.find(filter);
		if (list != null && !list.isEmpty()) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<OrderInfo> getGroupOrderList(Long groupId) {
		QueryFilter filter = new DynamicSQLFilterImpl();
		filter.addFilter("Q_groupOrderId_L_EQ", groupId + "");
		filter.setPagingBean(null);
		List<OrderInfo> list = dao.find(filter);
		return list;
	}

	@Override
	public void batchSave(List<OrderInfo> list) {
		for (OrderInfo order : list) {
			dao.insert(order);
		}
	}

	@Override
	public OrderInfo getByCardNumber(String cardNumber) {
		QueryFilter filter = new DynamicSQLFilterImpl();
		filter.addFilter("Q_cardNumber_S_EQ", cardNumber);
		List<OrderInfo> list = dao.find(filter);
		if(list != null && !list.isEmpty()){
			return list.get(0);
		}
		return null;
	}

	@Override
	public OrderInfo getByCardNumberAndPwd(String cardNumber, String password) {
		QueryFilter filter = new DynamicSQLFilterImpl();
		filter.addFilter("Q_cardNumber_S_EQ", cardNumber);
		filter.addFilter("Q_cardPassword_S_EQ", password);

		List<OrderInfo> list = dao.find(filter);
		if(list != null && !list.isEmpty()){
			return list.get(0);
		}
		return null;
	}
	@Override
	public List<OrderInfo> getByIdentifyAndName(String identify, String endUser) {
		QueryFilter filter = new DynamicSQLFilterImpl();
		filter.addFilter("Q_idCard_S_EQ", identify);
		filter.addFilter("Q_endUser_S_EQ", endUser);
		filter.addFilter("Q_bespeaked_S_NOTNULL", "0");
		filter.addFilter("Q_bespeaked_S_NEQ", "1");

		return dao.find(filter);
	}
	@Override
	public void updateReserveStatus(Long id, String reserveStatus) {
		dao.updateReserveStatus(id, reserveStatus);
	}
}
